var w,h,className;
function getSrceenWH(){
    w = $(window).width();
    h = $(window).height();
    $('#dialogBg').width(w).height(h);
}

window.onresize = function(){
    getSrceenWH();
}
$(window).resize();

$(function(){
    getSrceenWH();

    //显示弹框
    $('.rollIn').click(function(){
        className = $(this).attr('class');
        $('#dialogBg').fadeIn(300);
        $('#dialog').removeAttr('class').addClass('animated '+className+'').fadeIn();
    });

    //关闭弹窗
    $('.claseDialogBtn').click(function(){
        $('#dialog').addClass('bounceOutUp').fadeOut();
        $('#dialogBg').fadeOut(1000);
    });
});

$().ready(function() {
// 在键盘按下并释放及提交后验证提交表单
    $("#editForm").validate({
        rules: {
            nickname: "required",
            title: "required",
            content: "required"
        },
        messages: {
            nickname: "请输入您的昵称",
            title: "请输入标题",
            content: "请输入正文"
        },
        submitHandler:function(form){
            $.ajax({
                url: "/navigation/userrecommend/save",
                type: "post",
                data: JSON.stringify($("#editForm").serializeObject()),
                headers: {
                    "X-Auth-Token": "open-sesame",
                    "Content-Type": "application/json"
                },
                contentType: 'text/html; charset=UTF-8',
                success: function(data) {
                    console.log(data)
                    if(data.code == 0) {
                        $(".claseDialogBtn").click();
                        alert('保存成功');
                        document.getElementById("editForm").reset();
                    } else {
                        alert('保存失败!');
                    }
                }
            });
            return false;
        }
    })
});